package service

import (
	//	"github.com/jinzhu/gorm"
	"fmt"
	//	"initRoute"
	//	"controller"
	//"dbdata"
	//	"encoding/json"
	"net/http"
	"cmsapi/src/lib"
	"cmsapi/src/model"

	"github.com/gin-gonic/gin"
	//"github.com/gomodule/redigo/redis"
	//"database/sql"
	//"time"
	//	_ "github.com/go-sql-driver/mysql"
	//"gorm.io/driver/mysql"
	//"gorm.io/gorm"
	//"gorm.io/driver/mysql"
	//"gorm.io/gorm"
	//"gorm.io/gorm/logger"
)

type Data2 struct {
	//ActivityStruct
	////Content string `json:"Content" binding:"required"` //`资讯内容
	//List interface{ model.ActivityData } `json:"activitydata"`
}

//资讯详细2
func ActGormDetail(c *gin.Context) {
	data := model.ActivityData{}
	id := c.Query("id")
	/*
		dsn := "root:root@tcp(127.0.0.1:3306)/txgo?charset=utf8mb4&parseTime=True&loc=Local"
		//db, _ := gorm.Open(dsn)

		db, _ := gorm.Open(mysql.Open(dsn), &gorm.Config{
			Logger: logger.Default.LogMode(logger.Silent),
		})
	*/

	//db.LogMode(true)
	lib.Mysql.Debug().Table("tx_activity").Where("id = ?", id).First(&data) //Debug().
	//redis.String()
	//	db.Raw("SELECT * FROM users WHERE id = ?", 1).Scan(&data)
	//return data
	//t := []string{"abc", "oscar"}

	_, _ = lib.RedisSet("test1", "abc", 123)
	_, _ = lib.RedisSet("test2", []string{"abcc"}, 123)
	_, _ = lib.RedisSet("test3", []int{1, 2, 3, 4, 5}, 123)

	t := map[string]string{"a": "b"}
	//	fmt.Printf("t4 %s=>%T | %s=>%T   \r\n", t, t, t, t)
	s, _ := lib.RedisSet("test4", t, 123)
	fmt.Println(s)

	_, _ = lib.RedisGet("test1")
	_, _ = lib.RedisGet("test2")
	_, _ = lib.RedisGet("test3")
	v, _ := lib.RedisGet("test4")
	//v, _ := lib.Get("testw")
	fmt.Printf("c %s=>%T   \r\n", v, v)
	//for key, value := range v {
	//		fmt.Printf("c %s=>%T | %s=>%T   \r\n", key, key, value, value)
	//}

	//count :=
	//fmt.Println(count)
	/*
		for i := 0; i < count; i++ {
			fmt.Println(v.Index(i))
		}
	*/
	c.JSON(http.StatusOK, data)
}
